import request from '@/utils/request'
import moment from 'moment'
// 模仿接口 返回权限配置 操作按钮
export function getPermission() {
  return {
    coAdmin: ['detail', 'regular', 'transfer', 'dimisstion', 'role', 'delete'],
    user: ['detail']
  }
}

export function getEmployeesSimple() {
  return request({
    url: '/sys/user/simple',
    method: 'GET'
  })
}
/**
 * 获取员工的综合列表数据
 * ***/
export function getEmployeeList(params) {
  return request({
    url: '/sys/user',
    params
  }).then((res) => {
    return {
      ...res,
      rows: res.rows.map((row, idx) => {
        return {
          ...row,
          formOfEmployment: row.formOfEmployment ? '在职' : '不在职',
          enableState: row.enableState ? '可用' : '不可用',
          timeOfEntry: moment(row.timeOfEntry).format('YYYY-MM-DD'),
          index: params.size * (params.page - 1) + idx + 1
        }
      })
    }
  })
}

/**
 * 删除员工接口
 * ****/

export function delEmployee(id) {
  return request({
    url: `/sys/user/${id}`,
    method: 'delete'
  })
}

/** **
 *  新增员工的接口
 * **/
export function addEmployee(data) {
  return request({
    method: 'post',
    url: '/sys/user',
    data
  })
}

/** *
 *  封装一个导入员工的接口
 *
 * ***/

export function importEmployee(data) {
  return request({
    url: '/sys/user/batch',
    method: 'post',
    data
  })
}
